package com.study.lilhan.niuke.demo.linkPointer;

import com.study.lilhan.niuke.demo.bean.ListNode;

/**
 * @Author: lihan
 * @Date : 2022/1/4- 01
 * @DESCRIPTION: 分为三种情况后，接下来，遍历一个链表时，如何记录这个节点的信息
 * @version: 1.0
 */
public class My66 {
    public static void main(String[] args) {

    }

    public static  ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
//求出链表1,2的环节点的开始节点
        ListNode linkHead1 = findStartNode(pHead1);
        ListNode linkHead2 = findStartNode(pHead2);
//两个链表都没有环
        if(linkHead1 ==null && linkHead2 == null){

        }
//两个链表都有环
        if(linkHead1 != null && linkHead2 != null){

        }
 //一个链表有环，一个链表没有环，不相交

        return null;
    }

    public static ListNode findStartNode(ListNode head){
        if(head == null){
            return null;
        }
        ListNode qucikNode = head;
        ListNode slowNode = head;
        while (qucikNode.next != null && qucikNode.next.next != null){
            qucikNode = qucikNode.next.next;
            slowNode = slowNode.next;
            if(qucikNode == slowNode){
                return slowNode;
            }
        }
        return null;
    }
}
